package javaBase.nowcoder.HJ24_S_合唱队;

import java.util.*;
/*
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4?tpId=37&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3FjudgeStatus%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=1&tags=&title=&gioEnter=menu
 */
public class Main{

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int[] stu=new int[n];
        for(int i=0;i<n;i++){
            stu[i]=in.nextInt();
        }
        in.close();
        if(stu.length<3){
            return;
        }

        int[] leftNum=new int[n];
        int[] rightNum=new int[n];

        for(int i=1;i<n;i++){
            for(int j=0;j<i;j++){
                if(stu[j]<stu[i]){
                    leftNum[i]=Math.max(leftNum[j]+1,leftNum[i]);
                }
            }
        }

        for(int i=n-2;i>-1;i--){
            for(int j=n-1;j>i;j--){
                if(stu[j]<stu[i]){
                    rightNum[i]=Math.max(rightNum[j]+1,rightNum[i]);
                }
            }
        }
        int max=0;
        for(int i=0;i<n;i++){
            max=Math.max(max,leftNum[i]+rightNum[i]+1);
        }

        System.out.println(n-max);

    }
}